<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use App\Service\SystemService;
use App\Service\CommService;
#[AutoController]
class SystemController
{
    #[Inject]
    private SystemService $systemService;

    #[Inject]
    private CommService $commService;

    public function message(RequestInterface $request)
    {
        $user_message = $this->systemService->user_message();
        return [
            "code"=>10000,
            "message"=>"成功",
            "content"=>$user_message,
        ];
    }
    
    public function banner(RequestInterface $request){
        $banner_list = $this->systemService->banner_list();
        return [
            "code"=>10000,
            "message"=>"成功",
            "content"=>$banner_list,
        ];
    }

    public function popup_goods(RequestInterface $request){
        $user_id = $request->input('user_id', '');
        if (empty($user_id)){
            return [
                "code"=>20011,
                "message"=>"用户ID为空！",
                "content"=>(object)[],
            ];
        }
        $user_id = (int)$user_id;
        $rec = $this->commService->get_user_home_popup_goods($user_id);
        if ($rec){
            $goods_info = $this->systemService->popup_goods_info();
        }else{
            $goods_info = (object)[];
        }
        if (empty((array)$goods_info)){
            return [
                "code"=>20040,
                "message"=>"没有推荐商品",
                "content"=>$goods_info,
            ];
        }else{
            return [
                "code"=>10000,
                "message"=>"成功",
                "content"=>$goods_info,
            ];
        }


    }

    public function common_problem(RequestInterface $request){
        # 常见问题
        $info = $this->systemService->common_problem(2);
        return [
            "code"=>10000,
            "message"=>"成功",
            "content"=>$info,
        ];
    }

    public function use_rules(RequestInterface $request){
        # 使用规则
        $info = $this->systemService->common_problem(1);
        return [
            "code"=>10000,
            "message"=>"成功",
            "content"=>$info,
        ];
    }






}
